<%@ page contentType="text/html;charset=utf-8"%>	
 
 <%@ page import="com.yztc.rc.api.framework.ContextFactory" %>
<%@ page import="com.yztc.rc.api.framework.Context" %>
<%@ page import="com.yztc.rc.api.framework.entity.UserAccount" %>

<%
String path=request.getContextPath();

String url=request.getRequestURI(); 

UserAccount ua = (UserAccount)session.getAttribute(ContextFactory.FRAMEWORKSESSIONKEY);
/*Context context=ContextFactory.getContext();
UserAccount ua=null;
if(context!=null){
	ua=context.getUserAccount();
}*/
%>
<script type="text/javascript" src="<%=path%>/include/js/jquery.js" charset="UTF-8"></script>
<script>
	 
	function submitForm(){
	if(validate()){
		var pars = $("#frmLogin").serialize();
		 
		var url = '<%=com.yztc.rc.api.framework.ContextFactory.SSOLOGINURL%>';
		var pars = $("#frmLogin").serialize();
		url+="?"+pars+"&callback=?&n="+ new Date().getTime();
		//$("#txt_error").html("正在进行登录验证，请稍候...");
	    $.getJSON(url,function(data){
	   
	    	if(data && data.isSuccess){
	    	 
	    	//	$("#txt_error").html("验证通过正在进入系统，请稍候...");
	    		window.location.href="<%=path%>/jsp/openCms.jsp?url="+encodeURIComponent (window.location.href);
	    	}else{
	    	 
	    		flushLoginTicket();
	    		//暂时无效
	            //$('#lt').val(data.ticket);
	            //$('#execution').val(data.fek);
	    		var er = "";
	    		if("-1"==data.errorType)er = "您输入的用户名不存在，请更换用户名";//密码错误
	    		else if("-2"==data.errorType)er = "您输入的用户名密码错误，请重试\n超过3次失败，将在15分钟不能再次登录";//密码错误
	    		else if("-3"==data.errorType)er = "您输入的用户已被系统锁定，请联系管理员";
	    		else if("-4"==data.errorType)er = "您输入的用户已被删除，请联系管理员";
	    		else if("-5"==data.errorType)er = "您输入的用户已超过3次失败，将在15分钟不能再次登录";
	    		else if("-6"==data.errorType)er = "系统出现未知异常，请联系管理员";
	    		alert(er);
	    		//$("#txt_error").html(er);
	    	}
	    });
	}
}
function validate() {
    if ($("#P_loginname").val() == "") {
        alert("用户名不能为空");
        return false;
    }
    if ($("#P_loginpwd").val() == "") {
        alert("密码不能为空");
        return false;
    }
    return true;
}
var flushLoginTicket = function(){
    var url = '<%=com.yztc.rc.api.framework.ContextFactory.SSOLOGINURL%>?ajax-lt=true&get-lt=true&callback=?&n='+ new Date().getTime();
    $.getJSON(url,function(data){ 
        $('#lt').val(data.lt);
        $('#execution').val(data.fek); 
    });
};

function logOut() {
   // alert(encodeURIComponent (window.location.href));
    if(confirm("确定退出系统吗？")){
    	window.location.href = "<%=path%>/loginout.jsp?loginPage="+encodeURIComponent (window.location.href);
    } 
}

</script>

<%if(ua==null){ %>

 	<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:12px;">
				<tr>
					
					<td width="65%" align="left">
						<form id="frmLogin" method="post" action="<%=path%>/cms/login"  >
						 <input type="hidden" name="isajax" value="true" />
				        <input type="hidden" name="lt" id="lt" value="" />
				        <input type="hidden" name="execution" id="execution" value="" />
						<input type="hidden" name="ui" value="menu" checked />
						<input type="hidden" name="_eventId" value="submit" />
       					<input type="hidden" name="service" id="service" value="http://localhost/cms/jsp/openCms.jsp?url=<%=url%>" />
        
							用户名&nbsp;<input type="text" id="P_loginname"   name="username"    />&nbsp;密码&nbsp;<input  type="password" id="P_loginpwd"   name="password"/>&nbsp;<input name="Input" type="button" value="登录"  style="vertical-align:middle" class="button_login"  id="btnLogin" onclick="submitForm();" />&nbsp;&nbsp;&nbsp;&nbsp;
						<A href="/SSTA/register/register.jsp">注册新用户</A>
						</form> 
						
					</td>
				</tr>
			</table>
			
<%}else{ %>	
	
	
	 	<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:12px;">
				<tr>
					
					<td width="65%" align="left">
						 欢迎您，<%=ua.getLoginName() %>  登录安科网，
						 <A href="/SSTA/membercenter/userInfo.jsp" target="_blank">【会员中心】</A>
						 <A href="javascript:logOut()" >退出</A>
					</td>
				</tr>
			</table>
			

<%} %>	
			
 <script>
 <%if(ua==null){ %>
 flushLoginTicket();
 <%}%>
 </script>